package com.sysolve.betterCity.model;

public class HotArea {
	public int id;
	public int latMin;
	public int latMax;
	public int lngMin;
	public int lngMax;
	public int height;
	
	public HotArea(Place place, int radius, int height) {
		this.latMin = place.getLat() - radius;
		this.latMax = place.getLat() + radius;
		this.lngMin = place.getLng() - radius;
		this.lngMax = place.getLng() + radius;
		this.height = height;
	}
	
	public boolean isPlaceNearBy(Place p, int radius) {
		if ((p.getLat() < latMax+radius && p.getLat() > latMin-radius)
				&&
				(p.getLng() < lngMax+radius && p.getLng() > lngMin-radius))
			return true;
		else
			return false;
	}
	
	public void addPlace(Place p, int radius, int height) {
		setLatMin(p.lat-radius<getLatMin()?p.lat-radius:getLatMin());
		setLatMax(p.lat+radius>getLatMax()?p.lat+radius:getLatMax());
		setLngMin(p.lng-radius<getLngMin()?p.lng-radius:getLngMin());
		setLngMax(p.lng+radius>getLngMax()?p.lng+radius:getLngMax());
		setHeight(getHeight()+height);
	}
	
	public void addHotArea(HotArea hotArea) {
		setLatMin(hotArea.getLatMin()<getLatMin()?hotArea.getLatMin():getLatMin());
		setLatMax(hotArea.getLatMax()>getLatMax()?hotArea.getLatMax():getLatMax());
		setLngMin(hotArea.getLngMin()<getLngMin()?hotArea.getLngMin():getLngMin());
		setLngMax(hotArea.getLngMax()>getLngMax()?hotArea.getLngMax():getLngMax());
		setHeight(getHeight()+hotArea.getHeight());
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getLatMax() {
		return latMax;
	}

	public void setLatMax(int latMax) {
		this.latMax = latMax;
	}

	public int getLatMin() {
		return latMin;
	}

	public void setLatMin(int latMin) {
		this.latMin = latMin;
	}

	public int getLngMax() {
		return lngMax;
	}

	public void setLngMax(int lngMax) {
		this.lngMax = lngMax;
	}

	public int getLngMin() {
		return lngMin;
	}

	public void setLngMin(int lngMin) {
		this.lngMin = lngMin;
	}
	public int getCenterLng() {
		return (getLngMax()+getLngMin())/2;
	}
	public int getCenterLat() {
		return (getLatMax()+getLatMin())/2;
	}
}
